<template>
  <div class="mod-config">
    <table-view ref="view"
                :searchAttrs="searchAttrs"
                :primaryKey="primaryKey"
                :listApiName="listApiName"
                :deleteApiName="deleteApiName"
                :saveAuthName="saveAuthName"
                :deleteAuthName="deleteAuthName"
                :templateDownloadApiName="templateDownloadApiName"
                :importApiName="importApiName"
                :showAttrs="showAttrs"
                :multiAdd="true"
    >
      <template v-slot:header>
        <el-button size="small" type="warning" @click="openChartDialog">图表</el-button>
      </template>
    </table-view>
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    <productinfo-add-or-update v-if="productInfoVisible" ref="productInfo"></productinfo-add-or-update>
    <client-info-add-or-update v-if="clientInfoVisible" ref="clientInfo"></client-info-add-or-update>
    <!--  图表对话框  -->
    <normal-chart-dialog ref="charDialog"
                         :chartSearchObj="chartSearchObj"
                         :commitChartSearch="commitChartSearch"
    >
      <template v-slot:chart="{chart}">
        <chart ref="chart"></chart>
      </template>
    </normal-chart-dialog>
  </div>
</template>

<script>
import AddOrUpdate from './productputinstorage-add-or-update-1.vue'
import tableView from '@/components/tableView'
import basicMixins from '@/utils/commonViewMixins'
import ProductinfoAddOrUpdate from '@/views/modules/product/productinfo-add-or-update'
import chart from '@/views/charts/product/productInCategoryWeightChart'
import ClientInfoAddOrUpdate from '@/views/modules/client/clientinfo-add-or-update.vue'
import {mRequest} from '@/utils/request'

export default {
  mixins: [basicMixins],
  data() {
    return {
      chartSearchObj: {
        dataForm: {
          dateTimeRange: []
        },
        config: {
          dateTimeRange: {
            type: 'date',
            clearable: true,
            dateType: 'daterange',
            label: '时间范围'
          }
        }
      },
      dataForm: {},
      clientInfoVisible: false,
      productInfoVisible: false,
      searchAttrs: {
        productId: {
          type: 'autoComplete',
          placeholder: '请选择产品',
          querySearchApiName: 'productApi/getProductInfoList'
        },
        clientId: {
          placeholder: '客户名称',
          type: 'autoComplete',
          querySearchApiName: 'clientApi/getClientList'
        },
        dateTimeRange: {
          type: 'date',
          dateType: 'daterange',
          clearable: true
        }
      },
      primaryKey: 'id',
      listApiName: 'productApi/listProductPutInStorage',
      deleteApiName: 'productApi/deleteProductPutInStorage',
      saveAuthName: 'product:productputinstorage:save',
      deleteAuthName: 'product:productputinstorage:delete',
      templateDownloadApiName: 'productApi/templateDownloadProductPutInStorage',
      importApiName: 'productApi/importProductPutInStorage',
      showAttrs: {
        location: {label: '存放位置'},
        productWeight: {label: '克数', type: 'tag'},
        boxZhiNumber: {label: '箱只'},
        boxNumber: {label: '箱数'},
        assortBoxNumber: {label: '配箱数量'},
        assortBoxZhiNumber: {label: '配箱只数'},
        tailBoxNumber: {label: '尾箱数量'},
        tailBoxZhiNumber: {label: '尾箱只数'},
        scrapNumber: {label: '零头'},
        countProductNumber: {label: '总数量', type: 'tag', width: 130},
        putInTime: {label: '日期', type: 'date', width: 110},
        productNo: {
          label: '产品编号',
          type: 'linkLabel',
          routerName: 'product-product-info-all',
          searchKey: 'productNo',
          width: 130
        },
        clientName: {
          label: '客户名称',
          type: 'linkLabel',
          routerName: 'client-clientinfo',
          searchKey: 'clientName'
        },
        salesperson: {
          label: '销售'
        },
        // },
        remark: {label: '备注'},
        // putInType: {
        //   label: '产品来源方式',
        //   type: 'radio',
        //   items: [
        //     {value: 0, text: '三和自产'},
        //     {value: 1, text: '外协-来料加工', tagType: 'danger'}
        //   ],
        //   width:90
        orderNo: {label: '订单编号', width: 130}
        // status: {
        //   label: '状态',
        //   type: 'radio',
        //   items: [
        //     {value: 0, text: '禁用', tagType: 'danger'},
        //     {value: 1, text: '正常'}
        //   ]
        // }
      },
      pickerOptions: {
        shortcuts: [{
          text: '今天',
          onClick(picker) {
            picker.$emit('pick', new Date());
          }
        }, {
          text: '昨天',
          onClick(picker) {
            const date = new Date();
            date.setTime(date.getTime() - 3600 * 1000 * 24);
            picker.$emit('pick', date);
          }
        }, {
          text: '一周前',
          onClick(picker) {
            const date = new Date();
            date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', date);
          }
        }]
      }
    }
  },
  methods: {
    dataFormSubmit() {
      mRequest('productApi/multipleSaveProductPutInStorage', {
        'putInTime': this.putInTime,
        'tableListData': this.tableListData
      }, (data) => {
        if (data.data.code === 0) {
          this.$message({
            message: '操作成功',
            type: 'success',
            duration: 1500
          })
        } else {
          this.$message.error(data.data.msg)
        }
        this.getDataList()
        this.deepDialogVisible = false
      })
    },
   openProductInfoDialog(cb) {
      this.productInfoVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.productInfo)) {

          this.$refs.productInfo.init(null, {status: 1}, cb)
        }
      })
    },
    openClientInfoDialog(cb) {
      this.clientInfoVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.clientInfo)) {
          this.$refs.clientInfo.init(null, {status: 1}, cb)
        }
      })
    }
  },
  components: {
    ProductinfoAddOrUpdate,
    ClientInfoAddOrUpdate,
    AddOrUpdate,
    tableView,
    chart
  }
}
</script>
